﻿@model PhoneBilling.Models.BackupMgtModel
@{
    ViewBag.Title = "数据库备份还原";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="backup_mgt">
    <div class="system_contain_group">
        <h3 class="title">
            手动备份与还原</h3>
        @using (Html.BeginForm("Backup", "System", FormMethod.Post, new { id = "backupForm", enctype = "multipart/form-data" }))
        {
            <div class="system_input_contain">
                <input type="button" id="btnBackup" value="数据库备份" />
            </div>
        }
        <script type="text/javascript">
            $(document).ready(function () {
                $("#btnBackup").ligerButton(
        {
            click: function () {
                $("#backupForm").submit();
            }
        });

                $("#btnConfirm").ligerButton(
        {
            click: function () {
                $('#settingForm').submit();
            }
        });

                changeIsAutoBackup();
            });
        </script>
        @using (Html.BeginForm("Restore", "System", FormMethod.Post, new { enctype = "multipart/form-data", id = "restoreForm" }))
        {
            <div class="system_input_contain">
                <input type="file" value="数据库还原" id="btnRestore" name="file" onchange="$('#restoreForm').submit();" />
            </div>
        }
    </div>
    @using (Html.BeginForm("BackupMgt", "System", FormMethod.Post, new { enctype = "multipart/form-data", id = "settingForm" }))
    {
        <div class="system_contain_group">
            <h3 class="title">
                自动备份设置</h3>
            <div class="system_input_contain system_checkbox">
                @Html.CheckBoxFor(m => m.IsAutoBackup, new { onclick = "changeIsAutoBackup()", @class = "isAuto" })
                @Html.LabelFor(m => m.IsAutoBackup)
            </div>
            <div class="system_input_contain system_checkbox">
                @Html.RadioButtonFor(m => m.BackupCycle, "按月备份", new { onclick = "s1Change()", @class = "s1" })
                <label>
                    按月备份</label>
                @Html.LabelFor(m => m.MonthValue)
                @Html.TextBoxFor(m => Model.MonthValue, new { @class = "s1d" })
                @Html.ValidationMessageFor(m => m.MonthValue, new { style = "color:Red" })
            </div>
            <div class="system_input_contain system_checkbox">
                @Html.RadioButtonFor(m => m.BackupCycle, "按周备份", new { onclick = "s2Change()", @class = "s2" })
                <label>
                    按周备份</label>
                @Html.LabelFor(m => m.MonthValue)
                @Html.DropDownListFor(m => m.WeekValue, new SelectList(Model.WeekValueList), new { style = "input-text", @class = "s2d" })
                @Html.ValidationMessageFor(m => m.WeekValue, new { style = "color:Red" })
            </div>
            <div class="system_input_contain system_checkbox">
                @Html.RadioButtonFor(m => m.BackupCycle, "按日备份", new { @class = "s3" })
                <label>
                    按日备份</label>
            </div>
            <div class="system_input_contain system_checkbox">
                @Html.LabelFor(m => m.BackupTime)
                @Html.TextBox("BackupTime", Model.BackupTime.ToString("HH:mm:ss"), new { @class = "backupTime" })
                @Html.ValidationMessageFor(m => m.BackupTime, new { style = "color:Red" })
            </div>
            <div class="system_input_contain">
                @Html.LabelFor(m => m.AutoBackupPath)
                @Html.TextBox("AutoBackupPath", Model.AutoBackupPath)
                @Html.ValidationMessageFor(m => m.AutoBackupPath, new { style = "color:Red" })
            </div>
            <div class="system_input_contain">
                <input type="button" id="btnConfirm" value="确定" />
            </div>
        </div>
    }
    <script type="text/javascript">
        function changeIsAutoBackup() {
            var isAuto = $(".isAuto").attr("checked") == "checked";
            if (isAuto) {
                $(".s1").attr("disabled", false);
                $(".s1d").attr("disabled", $(".s1").attr("checked") != "checked");
                $(".s2").attr("disabled", false);
                $(".s2d").attr("disabled", $(".s2").attr("checked") != "checked");
                $(".s3").attr("disabled", false);
                $(".backupTime").attr("disabled", false);
            }
            else {
                $(".s1").attr("disabled", true);
                $(".s1d").attr("disabled", true);
                $(".s2").attr("disabled", true);
                $(".s2d").attr("disabled", true);
                $(".s3").attr("disabled", true);
                $(".backupTime").attr("disabled", true);
            }
        }
        function s1Change() {
            var isAuto = $(".isAuto").attr("checked") == "checked";
            if (isAuto) {
                if ($(".s1").attr("checked") == "checked") {
                    $(".s1d").attr("disabled", false);
                    $(".s2d").attr("disabled", true);
                }
                else {
                    $(".s1d").attr("disabled", true);
                    $(".s2d").attr("disabled", false);
                }
            }
            else {
                $(".s1d").attr("disabled", true);
                $(".s2d").attr("disabled", true);
            }
        }
        function s2Change() {
            var isAuto = $(".isAuto").attr("checked") == "checked";
            if (isAuto) {
                if ($(".s2").attr("checked") == "checked") {
                    $(".s1d").attr("disabled", true);
                    $(".s2d").attr("disabled", false);
                }
                else {
                    $(".s1d").attr("disabled", false);
                    $(".s2d").attr("disabled", true);
                }
            }
            else {
                $(".s1d").attr("disabled", true);
                $(".s2d").attr("disabled", true);
            }
        }
    </script>
</div>
